<?php

    class itComplexRulesTest extends itTestCase {
        
        /**
         * @test
         */
        public function testGetSet() {
            $s = new itComplexRules();
            $s->setPrefix('A');
            $this->assertEquals('A', $s->getPrefix());
            $this->assertFalse($s->isStrictExtensions());
            $this->assertFalse($s->isDotDirEnabled());
            $this->assertEquals(array('php'), $s->getExtensions());
        }
        
        /**
         * @test
         */
        public function testPlusFile() {
            $prefix = TEST_DATA.'/Individual/Rules/Complex/A/';
            $complex = new itComplexRules();
            $complex->setPrefix($prefix);
            $complex->plusFile('A1/A1_1.php');
            $complex->plusFile('A1/A1_1/A1_1_1.php');
            $simple = $complex->toSimpleRules();
            $this->assertEquals(2, count($simple->toArray()));
        }
        
        /**
         * @test
         */
        public function testPlusDir() {
            $prefix = TEST_DATA.'/Individual/Rules/Complex/A/';
            $complex = new itComplexRules();
            $complex->setPrefix($prefix);
            $complex->plusDir('A1/A1_1');
            $simple = $complex->toSimpleRules();
            $this->assertEquals(3, count($simple->toArray()));
            $complex->plusDir('A1/A1_2');
            $simple = $complex->toSimpleRules();
            $this->assertEquals(6, count($simple->toArray()));
        }
        
        /**
         * @test
         */
        public function testPlusDirRecursive() {
            $prefix = TEST_DATA.'/Individual/Rules/Complex/A/';
            $complex = new itComplexRules();
            $complex->setPrefix($prefix);
            $complex->plusDir('A1', true);
            $simple = $complex->toSimpleRules();
            $this->assertEquals(8, count($simple->toArray()));
        }
        
        /**
         * @test
         */
        public function testMinusFile() {
            $prefix = TEST_DATA.'/Individual/Rules/Complex/A/';
            $complex = new itComplexRules();
            $complex->setPrefix($prefix);
            $complex->plusDir('A1', true);
            $complex->minusFile('A1/A1_1.php');
            $simple = $complex->toSimpleRules();
            $this->assertEquals(7, count($simple->toArray()));
        }
        
        /**
         * @test
         */
        public function testMinusDir() {
            $prefix = TEST_DATA.'/Individual/Rules/Complex/A/';
            $complex = new itComplexRules();
            $complex->setPrefix($prefix);
            $complex->plusDir('A1', true);
            $complex->minusDir('A1/A1_1');
            $simple = $complex->toSimpleRules();
            $this->assertEquals(5, count($simple->toArray()));
        }
        
        /**
         * @test
         */
        public function testExtensions() {
            $prefix = TEST_DATA.'/Individual/Rules/Complex/A/';
            $complex = new itComplexRules();
            $complex->setPrefix($prefix);
            $complex->setExtensions('txt');
            $complex->plusDir('A2', true);
            $simple = $complex->toSimpleRules();
            $this->assertEquals(1, count($simple->toArray()));
            $complex->setExtensions(array('txt', 'strict.php'));
            $simple = $complex->toSimpleRules();
            $this->assertEquals(2, count($simple->toArray()));
            $complex->setExtensions('.txt');
            $complex->plusDir('A2', true);
            $simple = $complex->toSimpleRules();
            $this->assertEquals(1, count($simple->toArray()));
        }
        
        /**
         * @test
         */
        public function testStrictExtensions() {
            $prefix = TEST_DATA.'/Individual/Rules/Complex/A/';
            $complex = new itComplexRules();
            $complex
                ->setPrefix($prefix)
                ->setExtensions('php')
                ->setStrictExtensions()
                ->plusDir('A2', true)
            ;
            $simple = $complex->toSimpleRules();
            $this->assertEquals(8, count($simple->toArray()));
        }
        
        /**
         * @test
         */
        public function testDotDir() {
            $prefix = TEST_DATA.'/Individual/Rules/Complex/A/';
            $complex = new itComplexRules();
            $complex
                ->setPrefix($prefix)
                ->setExtensions('txt')
                ->plusDir('.', true)
            ;
            $simple = $complex->toSimpleRules();
            $this->assertEquals(1, count($simple->toArray()));
            $complex->setDotDirEnabled();
            $simple = $complex->toSimpleRules();
            $this->assertEquals(3, count($simple->toArray()));
        }
        
        /**
         * @test
         */
        public function testPhar() {
            if (!extension_loaded('Phar')) {
                return;
            }
            
            $complex = new itComplexRules();
            $complex->plusDir('phar://'.TEST_DATA.'/Shared/Phar/test.phar', true);
            $this->assertTrue(count($complex->toSimpleRules()->toArray()) > 0);
        }
    }
    
?>